package com.richie696.catalina;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class MappedEngine implements Engine {

    private String name;
    private String defaultHost;
    private final Map<String, Host> hosts = new ConcurrentHashMap<>(10);

    @Override
    public String getName() {
        return this.name;
    }

    @Override
    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String getDefaultHostName() {
        return this.defaultHost;
    }

    @Override
    public Host getDefaultHost() {
        return this.hosts.get(this.defaultHost);
    }

    @Override
    public void setDefaultHost(String defaultHost) {
        this.defaultHost = defaultHost;
    }

    @Override
    public void addHost(String name, String path) {
        if (this.hosts.containsKey(name)) {
            return;
        }
        this.hosts.put(name, new MappedHost(name, path));
    }

    @Override
    public Host getHost(String name) {
        return this.hosts.get(name);
    }

    @Override
    public List<Host> getHosts() {
        return new ArrayList<>(this.hosts.values());
    }

}
